﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;

using System.Data.Common;
using Mocola.BLL;
using Mocola.Model;

namespace Mocola.Net.Web.ajax
{
    public partial class AddMap : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MembershipCreateStatus status = new MembershipCreateStatus();
            DbTransaction transaction = Databases.MocolaNet.BeginTransaction(IsolationLevel.ReadCommitted);

            try
            {
                string pTid = getRequest("Tid");
                string pEid = getRequest("Eid");     
                string pMingCheng = getRequest("MingCheng");        // 名称
                string pJueDingHao = getRequest("JueDingHao");      // 决定号
                string pTuZhiBianHao = getRequest("TuZhiBianHao");  // 图纸编号
                string pZhuanYeLeiBie = getRequest("ZhuanYeLeiBie");  // 专业类别

                string pJiShouRiQi = getRequest("JieShouRiQi_Nian") + "-" + getRequest("JieShouRiQi_Yue") + "-" + getRequest("JieShouRiQi_Ri");      // 接收时间
                string pChuTuRiQi = getRequest("ChuTuRiQi_Nian") + "-" + getRequest("ChuTuRiQi_Yue") + "-" + getRequest("ChuTuRiQi_Ri");      // 竣工时间

                string pSheJiDanWei = getRequest("SheJiDanWei");           // 设计单位

                string pBanBen = getRequest("BanBen");          // 版本
                string pTuFu = getRequest("TuFu");              // 图幅
                string pZhang = getRequest("Zhang");            // 张
                string pTao = getRequest("Tao");                // 套
                string pShuLiang = getRequest("ShuLiang");              // 数量

                string pZaiTi = getRequest("ZaiTi");      // 载体

                string pCaiZhi = getRequest("CaiZhi");          // 材质
                string pMiJi = getRequest("MiJi");          // 密级
                string pBaoGuanQiXian = getRequest("BaoGuanQiXian");          // 保管期限

                //string pFaQiBuMen = "";          // 发起部门
                //string pYiJiaoRen = "";          // 移交人
                //string pJiShouRen = "";          // 接收人

                string pZhuangTai = getRequest("ZhuangTai");          // 状态
                string pBeiZhu = getRequest("BeiZhu");      // 备注

                int nID = Databases.MocolaNet.Insert(Moc_MapsInfo.Moc_Maps)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.Name, pMingCheng)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.JueDingHao, pJueDingHao)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.TuZhiBianHao, pTuZhiBianHao)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.ZhuanYeLeiBie, pZhuanYeLeiBie)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.ChuTuRiQi, pChuTuRiQi)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.SheJiDanWei, pSheJiDanWei)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.BanBen, pBanBen)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.TuFu, pTuFu)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.Zhang, pZhang)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.Tao, pTao)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.ShuLiang, pShuLiang)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.ZaiTi, pZaiTi)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.CaiZhi, pCaiZhi)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.MiJi, pMiJi)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.BaoGuanQiXian, pBaoGuanQiXian)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.ZhuangTai, pZhuangTai)
                                 //.AddColumn(Moc_MapsInfo.Moc_Maps.FaQiBuMen, pFaQiBuMen)
                                 //.AddColumn(Moc_MapsInfo.Moc_Maps.YiJiaoRen, pYiJiaoRen)
                                 //.AddColumn(Moc_MapsInfo.Moc_Maps.JiShouRen, pJiShouRen)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.JiShouRiQi, pJiShouRiQi)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.BeiZhu, pBeiZhu)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.Eid, pEid)
                                 .AddColumn(Moc_MapsInfo.Moc_Maps.Tid, pTid)
                                 .SetTransaction(transaction)
                                 .ExecuteReturnAutoIncrementID(Moc_MapsInfo.Moc_Maps.ID);

                bool blTrees = false;

                if (nID != -1)
                {
                    blTrees = true;
                }


                if (blTrees)
                {
                    Response.Write("新增图纸成功！");
                    status = MembershipCreateStatus.Success;
                }
                else
                {
                    Response.Write("新增图纸失败！");
                    status = MembershipCreateStatus.ProviderError;
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                status = MembershipCreateStatus.ProviderError;
            }
            finally
            {
                if (status == MembershipCreateStatus.Success)
                    transaction.Commit();
                else
                    transaction.Rollback();
                Databases.MocolaNet.CloseConnection(transaction);
            }
        }

        private string getRequest(string pReqID)
        {
            return string.IsNullOrEmpty(Request.Form[pReqID]) ? string.Empty : Request.Form[pReqID].ToString();
        }
    }
}
